<?php

/**
 * Pes for PHP 5.3+
 *
 * Copyright (c) 2013 phpeskill.com (http://www.pescms.com)
 *
 * For the full copyright and license information, please view
 * the file LICENSE.md that was distributed with this source code.
 */

namespace App\User;

use Core\Db\Db as Db;

/**
 * PSE前台首页
 * @author LazyPHP
 * @version 1.0
 */
class Index extends Common {

    public function __construct() {
        parent::__construct();
    }

    public function index() {
        $this->display();
    }

    /**
     * 基础信息
     */
    public function base() {
        $this->display();
    }

    /**
     * 安全设置
     */
    public function safe() {
        $this->display();
    }

    /**
     * 更新安全设置
     */
    public function updateSafe() {
        $data['uid'] = $_SESSION['user']['uid'];
        $oldpassword = md5(md5($this->is_p('oldpassword', '请输入原密码')));
        $data['password'] = md5(md5($this->is_p('password', '请填写登陆账号')));
        $repassword = md5(md5($this->is_p('repassword', '请填写登陆账号')));
        if($data['password'] != $repassword){
            $this->error('两次密码不一致!');
        }
        $db = $this->db('user');
        $correctPassword = $db->where('uid =:uid and password =:password')->find(array('uid' => $data['uid'], 'password' => $oldpassword));
        $this->determineSqlExecResult($correctPassword, '原密码不正确!');
        
        $updateResult = $db->where('uid =:uid')->save($data);
        $this->determineSqlExecResult($updateResult, '密码更新失败!');
        unset($_SESSION['user']);
        $this->success('密码更新成功,请重新登录!', $this->url('User-Login-index'));
        
    }

    /**
     * 最新消息
     */
    public function message() {
        $this->display();
    }

    /**
     * 反馈信息
     */
    public function feedback() {
        $this->display();
    }

    /**
     * 添加反馈
     */
    public function addFeed() {
        
    }

}